package flc.ast.adapter;

import android.widget.ImageView;

import androidx.annotation.NonNull;

import com.blankj.utilcode.util.ConvertUtils;
import com.blankj.utilcode.util.FileUtils;
import com.blankj.utilcode.util.TimeUtils;
import com.bumptech.glide.Glide;
import com.chad.library.adapter.base.provider.BaseItemProvider;
import com.chad.library.adapter.base.viewholder.BaseViewHolder;

import java.text.SimpleDateFormat;

import flc.ast.R;
import stark.common.basic.adaptermutil.StkProviderMultiAdapter;
import stark.common.basic.adaptermutil.StkSingleSpanProvider;

public class RecordAdapter extends StkProviderMultiAdapter<String> {

    public RecordAdapter() {
        addItemProvider(new StkSingleSpanProvider<>(35));
        addItemProvider(new RecordProvider());
    }

    private class RecordProvider extends BaseItemProvider<String> {
        @Override
        public int getItemViewType() {
            return StkProviderMultiAdapter.TYPE_VIEW;
        }

        @Override
        public int getLayoutId() {
            return R.layout.item_record;
        }

        @Override
        public void convert(@NonNull BaseViewHolder baseViewHolder, String bean) {
            Glide.with(baseViewHolder.itemView).load(bean).into((ImageView) baseViewHolder.getView(R.id.ivRecordItemImg));
            baseViewHolder.setText(R.id.tvRecordItemName, FileUtils.getFileName(bean));
            baseViewHolder.setText(R.id.tvRecordItemDate, TimeUtils.millis2String(FileUtils.getFileLastModified(bean), new SimpleDateFormat("yyyy-MM-dd")) + " " + ConvertUtils.byte2FitMemorySize(FileUtils.getFileLength(bean), 0));
        }
    }
}
